<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { equipApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray } from '@/utils'
  const action = reactive({
    gameList:[] as Array<any>,
    list:[] as any[],
    dateArr:getDateArray('time') as Array<number>
  })
  const listQuery = reactive({
    game_id:'',
  })
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      game_id:'',
    })
    getList()
  }
  const getGameIdList = async()=>{
    const res = await equipApi.gameSwitch()
    const { data=[] } = res || {}
    action.gameList = data
  }
  const getList = async()=> {
    const loading = Toastloading()
    const timeObi = getPlayEndTime(action.dateArr)
    const res = await equipApi.statSearchAll({
      ...listQuery,
      date_st:timeObi.playTime,
      date_ed:timeObi.endTime
    })
    loading.close()
    const { data=[] } = res || {}
    action.list = [data]
  }
  onMounted(()=>{
    getGameIdList()
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">游戏ID：</div>
          <el-select v-model="listQuery.game_id" clearable placeholder="请选择游戏ID">
            <el-option v-for="item in action.gameList" :label="item.game_name" :value="item.game_id" />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">时间：</div>
          <el-date-picker
            v-model="action.dateArr"
            type="datetimerange"
            format="YYYY-MM-DD HH:mm:ss "
            value-format="x"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="getList">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="userNum" label="人数" />
      <el-table-column min-width="120" prop="payNum" label="消耗金豆" />
      <el-table-column min-width="120" prop="getNum" label="参与产出金豆" />
      <el-table-column min-width="120" prop="auctionNum" label="系统回收金豆数" />
      <el-table-column min-width="120" prop="profitNum" label="利润金豆" />
      <el-table-column min-width="120" prop="profiRate" label="利润率">
        <template #default="scope">
          {{ scope.row.profiRate }}%
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
